<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>修改管理员</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />

</head>
<body>

<div class="formbody">

    <div class="formtitle">
        <span th:if="${model.id}==null">添加操作员</span>
        <span th:if="${model.id}!=null">编辑操作员</span>
    </div>


    <ul class="forminfo">
        <li><label>登录名</label>
            <input type="text" id="txtLoginName" name="txtLoginName" th:value="${model.userName}" class="dfinput" tyle="width:200px" />
        </li>
        <li><label>密码</label>
            <input type="text" id="txtPassword" name="txtPassword" th:value="${model.password}" class="dfinput" tyle="width:200px" />
        </li>
        <li><label>姓名</label>
            <input type="text" id="txtTrueName" name="txtTrueName" th:value="${model.realname}" class="dfinput"  style="width:200px" />
        </li>

        <li><label>状态</label>
            <select id="drpStatus" class="scinput">
                <option value="1" th:selected="(${model.status} =='1')">正常</option>
                <option value="-1" th:selected="(${model.status} =='-1')">冻结</option>
            </select>
        </li>


        <li><label>&nbsp;</label>
            <input type="button" id="btnSave" class="btn" value="保存" />
            <input type="hidden" id="hiddAdminId" th:value="${model.id}" />
        </li>
    </ul>
</div>


</body>
<script type="text/javascript" src="js/jquery.js"></script>
<link href="plugin/artDialog/artDialog/skins/blue.css" rel="stylesheet" />
<script src="plugin/artDialog/artDialog/artDialog.min.js" type="text/javascript"></script>
<script src="plugin/artDialog/artDialog/artDialog.plugins.min.js" type="text/javascript"></script>
<script src="plugin/artDialog/dialog.js" type="text/javascript"></script>
<script>
    /*<![CDATA[*/
    function save(id,userName, realName, pwd, status) {
        if (id){
            $.ajax({
                url: 'editAdmin',
                type: 'POST',
                data: {
                    'id' :id,
                    'userName': userName,
                    'realname':realName,
                    'password':pwd,
                    'status': status,
                },
                dataType: 'json',
                success: function (data) {
                    if (data.status == '0') {
                        showNotice('保存成功');
                        parent.location.reload();
                    } else {
                        showNotice(data.msg);
                    }
                }
            });}
        else {
            $.ajax({
                url: 'createAdmin',
                type: 'POST',
                data: {
                    'userName': userName,
                    'realName': realName,
                    'password': pwd,
                    'status': status,
                },
                dataType: 'json',
                success: function (data) {
                    if (data.status == '0') {
                        showNotice('保存成功');
                        parent.location.reload();
                    } else {
                        showNotice(data.msg);
                    }
                }
            });
        }
    }

    $(function () {
        $('#btnSave').click(function () {
            var id = $('#hiddAdminId').val();
            var userName = $('#txtLoginName').val();
            var realName = $('#txtTrueName').val();
            var pwd = $('#txtPassword').val();
            var status = $('#drpStatus').val();

            if (userName == '' || pwd == ''||realName=='') {
                alert('请填写完整信息');
                return false;
            }

            save(id,userName, realName, pwd, status);
        });
    });
    /*]]>*/
</script>
</html>